/**   
 * Copyright © 2016 深圳市欧唯科技有限公司. All rights reserved.
 * 
 * @Title: MyCredentialsMatcher.java 
 * @Prject: Web
 * @Package: com.adv.shiro 
 * @Description: TODO
 * @author: WUQINGLONG   
 * @date: 2016年9月7日 上午11:13:44 
 * @version: V1.0   
 */
package com.adv.shiro;

import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.adv.util.PasswordUtil;

/**
 * @ClassName: MyCredentialsMatcher
 * @Description: TODO
 * @author: WUQINGLONG
 * @date: 2016年9月7日 上午11:13:44
 */
public class SpecialPasswordCredentialsMatcher extends SimpleCredentialsMatcher {
	private static final Logger log = LoggerFactory.getLogger(SpecialPasswordCredentialsMatcher.class);

	protected boolean equals(Object tokenCredentials, Object accountCredentials) {
		if (log.isDebugEnabled()) {
			log.debug("Performing credentials equality check for tokenCredentials of type ["
					+ tokenCredentials.getClass().getName() + " and accountCredentials of type ["
					+ accountCredentials.getClass().getName() + "]");
		}
		if (isByteSource(tokenCredentials) && isByteSource(accountCredentials)) {
			if (log.isDebugEnabled()) {
				log.debug("Both credentials arguments can be easily converted to byte arrays.  Performing "
						+ "array equals comparison");
			}
			byte[] tokenBytes = toBytes(tokenCredentials);
			byte[] accountBytes = toBytes(accountCredentials);
			// return Arrays.equals(tokenBytes, accountBytes);
			return PasswordUtil.verify(new String(tokenBytes), new String(accountBytes));
		} else {
			return PasswordUtil.verify(tokenCredentials.toString(), accountCredentials.toString());
		}
	}

}
